package com.book.controller;


import com.book.pojo.ScoreRanking;
import com.book.result.Result;
import com.book.service.ScoreRankingService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cxy
 * @since 2023-10-13 14:50:19
 */
@RestController
@RequestMapping("/score-ranking")
public class ScoreRankingController {
    @Autowired
    private ScoreRankingService scoreRankingService;

    //评分榜表
    @GetMapping("ScoreRanking")
    public Result ScoreRanking (){
        List<ScoreRanking> list=scoreRankingService.ScoreRanking();
        return Result.OK().setData(list);
    }

    //删除一本书在评分榜里的评分
    @DeleteMapping("deleteByBookId")
    public void deleteByBookId(@RequestParam("bookId") Long bookId){
        scoreRankingService.deleteByBookId(bookId);
    }

    //增加一本书的评分的平均分
    @PostMapping("add")
    public void add(@RequestParam("bookId")Long bookId,@RequestParam("scoreAvg") Double scoreAvg){
        scoreRankingService.add(bookId,scoreAvg);
    }

}
